package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Tableshape;
import com.restaurant.service.TableshapeService;

public class TableshapeServiceImpl implements TableshapeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableshape addOrModify( Tableshape objTableshape ) {
       return ( Tableshape ) hibernateTemplate.merge( objTableshape );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableshape deleteRecord( Tableshape objTableshape ) {
       hibernateTemplate.delete( objTableshape );
       return objTableshape;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableshape modifyRecord( Tableshape objTableshape ) {
       return ( Tableshape ) hibernateTemplate.merge( objTableshape );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Tableshape> loadAll() {
       return (List<Tableshape>)hibernateTemplate.findByNamedQuery( "Tableshape.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableshape loadByPrimaryKey( Long primaryKey ) {
       return (Tableshape) hibernateTemplate.get( Tableshape.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableshape deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Tableshape> loadByHql(String query) {
       return ( List<Tableshape> ) hibernateTemplate.find( query );
   }
}